/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package putime.newspaperagent.product;

import java.awt.Color;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import putime.model.ModelProduct;
import putime.model.ModelSupplier;
import putime.newspaperagent.supplier.Supplier;
import sun.org.mozilla.javascript.internal.Function;

/**
 *
 * @author Administrator
 */
public class frmProduct extends javax.swing.JFrame {

    Vector<Product> vProduct;
    Vector vType;
    Vector vSp;
    ModelProduct modelProduct;
//    ModelSupplier modelSupplier;

    /**
     * Creates new form frmProduct
     */
    public frmProduct() {
        initComponents();
//        panelRateMagz.setVisible(false);
        setLocationRelativeTo(this);
        panelRateNews.setVisible(false);
        initcbBox();
    }

    public void initcbBox() {
        vType = new Vector();
        modelProduct = new ModelProduct();
        vType = modelProduct.initType();
        DefaultComboBoxModel dcm = new DefaultComboBoxModel(vType);
        cbTypeID.setModel(dcm);

        vSp = new Vector();
        vSp = modelProduct.getSup();
        DefaultComboBoxModel dcm2 = new DefaultComboBoxModel(vSp);
        cboSupplier.setModel(dcm2);

        initProdID();
        CbChange();
    }

    public void initProdID() {
        String chon = String.valueOf(cbTypeID.getSelectedItem());
        vProduct = new Vector<>();
        vProduct = modelProduct.initCobProd(chon, String.valueOf(cbTypeLang.getSelectedItem()));
        DefaultComboBoxModel dcm1 = new DefaultComboBoxModel(vProduct);
        cbTypeProdID.setModel(dcm1);

        DefaultListModel dlm = new DefaultListModel();
        for (Product prod : vProduct) {
            dlm.addElement(prod + "        " + prod.getProductName());
        }
        lstType.setModel(dlm);

        switch (chon) {
            case "Magazine":
                panelRateNews.setVisible(false);
                panelRateMagz.setVisible(true);
                break;
            case "Newspaper":
                panelRateNews.setVisible(true);
                panelRateMagz.setVisible(false);
                break;
            default:
                panelRateNews.setVisible(true);
                panelRateMagz.setVisible(false);
                break;
        }
    }

    public void CbChange() {
        String chon1 = String.valueOf(cbTypeProdID.getSelectedItem());
        Product product = modelProduct.ComboChange(chon1);
        txtProdID.setText(product.getProductID());
        txtPname.setText(product.getProductName());
        txtDescription.setText(product.getDescription());
        cboLanguage.setSelectedItem(product.getLanguage().trim());
        Supplier s = modelProduct.getSup(String.valueOf(product.getSupID()));
        cboSupplier.setSelectedItem(s.getSupName().trim());
        cboStatus.setSelectedIndex(product.getStatus());
    }

    public void findProduct(String chon) {
        ComboBoxModel model = cbTypeProdID.getModel();
        model.setSelectedItem(chon);
        Product tam = modelProduct.ComboChange(chon);
        cbTypeLang.setSelectedItem(tam.getLanguage().trim());
        ProductType t = modelProduct.getType(String.valueOf(tam.getTypeID()));
        cbTypeID.setSelectedItem(t.getTypeName().trim());
//        cbTypeID.setSelectedIndex(tam.getTypeID()-1);

    }

    public boolean CheckValidate() {
        Pattern patter = Pattern.compile("^[a-zA-Z][a-zA-Z\\s]*");
        Matcher matcher = patter.matcher(txtPname.getText());
        if (!matcher.matches()) {
            JOptionPane.showMessageDialog(this, "Wrong Name!, Please iput again!");
            return false;
        }
        return true;

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        cbTypeProd = new javax.swing.JPanel();
        cbTypeID = new javax.swing.JComboBox();
        cbTypeLang = new javax.swing.JComboBox();
        cbTypeProdID = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstType = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        panelRateNews = new javax.swing.JPanel();
        cbxMonday = new javax.swing.JCheckBox();
        cbxTuesday = new javax.swing.JCheckBox();
        cbxWednesday = new javax.swing.JCheckBox();
        cbxThursday = new javax.swing.JCheckBox();
        cbxFriday = new javax.swing.JCheckBox();
        cbxSaturday = new javax.swing.JCheckBox();
        cbxSunday = new javax.swing.JCheckBox();
        panelRateMagz = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        txtMagzRate = new javax.swing.JTextField();
        cboLanguage = new javax.swing.JComboBox();
        cboSupplier = new javax.swing.JComboBox();
        txtProdID = new javax.swing.JTextField();
        txtPname = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        cboStatus = new javax.swing.JComboBox();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        txtDescription = new javax.swing.JTextArea();
        btnFind = new javax.swing.JButton();
        btnNew = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        cbTypeProd.setBorder(javax.swing.BorderFactory.createTitledBorder("Type Product"));

        cbTypeID.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
        cbTypeID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTypeIDActionPerformed(evt);
            }
        });

        cbTypeLang.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Vietnamese", "English"}));
        cbTypeLang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTypeLangActionPerformed(evt);
            }
        });

        cbTypeProdID.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
        cbTypeProdID.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbTypeProdIDActionPerformed(evt);
            }
        });

        lstType.setModel(new javax.swing.AbstractListModel() {
            String[] strings = {"Item 1", "Item 2", "Item 3", "Item 4", "Item 5"};

            public int getSize() {
                return strings.length;
            }

            public Object getElementAt(int i) {
                return strings[i];
            }
        });
        lstType.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lstTypeValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(lstType);

        jLabel1.setText("Language");

        jLabel2.setText("ProductID");

        javax.swing.GroupLayout cbTypeProdLayout = new javax.swing.GroupLayout(cbTypeProd);
        cbTypeProd.setLayout(cbTypeProdLayout);
        cbTypeProdLayout.setHorizontalGroup(
                cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(cbTypeProdLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(cbTypeProdLayout.createSequentialGroup()
                .addComponent(jScrollPane1)
                .addContainerGap())
                .addGroup(cbTypeProdLayout.createSequentialGroup()
                .addComponent(cbTypeID, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cbTypeProdLayout.createSequentialGroup()
                .addGroup(cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1)
                .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cbTypeLang, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(cbTypeProdID, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)))));
        cbTypeProdLayout.setVerticalGroup(
                cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(cbTypeProdLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbTypeID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(cbTypeLang, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(cbTypeProdLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(cbTypeProdID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Detail"));

        jLabel3.setText("Product ID");

        jLabel4.setText("Product Name");

        jLabel5.setText("Language");

        jLabel6.setText("Supplier");

        panelRateNews.setBorder(javax.swing.BorderFactory.createTitledBorder("Rate"));

        cbxMonday.setText("Monday");

        cbxTuesday.setText("Tuesday");

        cbxWednesday.setText("Wednesday");

        cbxThursday.setText("Thursday");

        cbxFriday.setText("Friday");

        cbxSaturday.setText("Saturday");

        cbxSunday.setText("Sunday");

        javax.swing.GroupLayout panelRateNewsLayout = new javax.swing.GroupLayout(panelRateNews);
        panelRateNews.setLayout(panelRateNewsLayout);
        panelRateNewsLayout.setHorizontalGroup(
                panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelRateNewsLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cbxTuesday)
                .addComponent(cbxMonday))
                .addGap(18, 18, 18)
                .addGroup(panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cbxWednesday)
                .addComponent(cbxThursday))
                .addGap(10, 10, 10)
                .addGroup(panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelRateNewsLayout.createSequentialGroup()
                .addComponent(cbxFriday)
                .addGap(18, 18, 18)
                .addComponent(cbxSunday))
                .addComponent(cbxSaturday))
                .addContainerGap(36, Short.MAX_VALUE)));
        panelRateNewsLayout.setVerticalGroup(
                panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelRateNewsLayout.createSequentialGroup()
                .addGroup(panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(cbxMonday)
                .addComponent(cbxWednesday)
                .addComponent(cbxFriday)
                .addComponent(cbxSunday))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelRateNewsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(cbxTuesday)
                .addComponent(cbxThursday)
                .addComponent(cbxSaturday))));

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel7.setText("Rate");

        javax.swing.GroupLayout panelRateMagzLayout = new javax.swing.GroupLayout(panelRateMagz);
        panelRateMagz.setLayout(panelRateMagzLayout);
        panelRateMagzLayout.setHorizontalGroup(
                panelRateMagzLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelRateMagzLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(txtMagzRate, javax.swing.GroupLayout.PREFERRED_SIZE, 327, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        panelRateMagzLayout.setVerticalGroup(
                panelRateMagzLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelRateMagzLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelRateMagzLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(txtMagzRate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel7))
                .addGap(0, 11, Short.MAX_VALUE)));

        cboLanguage.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Vietnamese", "English"}));

        cboSupplier.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));

        txtProdID.setEditable(false);

        jLabel8.setText("Status");

        cboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Stop Selling", "Selling"}));

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Description"));

        txtDescription.setColumns(20);
        txtDescription.setRows(5);
        jScrollPane3.setViewportView(txtDescription);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE)
                .addContainerGap()));
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                .addContainerGap()));

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 30, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(panelRateMagz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(panelRateNews, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel3)
                .addComponent(jLabel4)
                .addComponent(jLabel5)
                .addComponent(jLabel6)
                .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(txtPname, javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cboLanguage, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cboSupplier, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cboStatus, javax.swing.GroupLayout.Alignment.LEADING, 0, 86, Short.MAX_VALUE)
                .addComponent(txtProdID))
                .addGap(34, 34, 34)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap()));
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel3)
                .addComponent(txtProdID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(txtPname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel5)
                .addComponent(cboLanguage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(cboSupplier, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel6))
                .addGap(21, 21, 21)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel8)
                .addComponent(cboStatus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(panelRateMagz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(panelRateNews, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap()));

        btnFind.setText("Find");
        btnFind.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFindActionPerformed(evt);
            }
        });

        btnNew.setText("New");
        btnNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNewActionPerformed(evt);
            }
        });

        btnEdit.setText("Edit");
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });

        btnDelete.setText("Delete");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(cbTypeProd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(btnFind)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnNew)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEdit)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDelete)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnCancel)
                .addGap(46, 46, 46)))
                .addContainerGap()));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(cbTypeProd, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnFind)
                .addComponent(btnNew)
                .addComponent(btnEdit)
                .addComponent(btnDelete)
                .addComponent(btnCancel))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cbTypeIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTypeIDActionPerformed
        // TODO add your handling code here:
        initProdID();
        CbChange();

    }//GEN-LAST:event_cbTypeIDActionPerformed

    private void cbTypeProdIDActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTypeProdIDActionPerformed
        // TODO add your handling code here:
        CbChange();
    }//GEN-LAST:event_cbTypeProdIDActionPerformed

    private void lstTypeValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstTypeValueChanged
        // TODO add your handling code here:
        cbTypeProdID.setSelectedIndex(lstType.getSelectedIndex());
    }//GEN-LAST:event_lstTypeValueChanged

    private void cbTypeLangActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTypeLangActionPerformed
        // TODO add your handling code here:
        initProdID();
        CbChange();
    }//GEN-LAST:event_cbTypeLangActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        // TODO add your handling code here:
        int tam = JOptionPane.showConfirmDialog(this, "You want delete Product Id: " + String.valueOf(cbTypeProdID.getSelectedItem()));
        if (tam == 0) {
            String chon = String.valueOf(cbTypeProdID.getSelectedItem());
            if (modelProduct.deleteProduct(chon)) {
                JOptionPane.showMessageDialog(this, "Delete Successfully!");
                initProdID();
            } else {
                JOptionPane.showMessageDialog(this, "Fail!!");
            }
        }
    }//GEN-LAST:event_btnDeleteActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindActionPerformed
        // TODO add your handling code here:
        FindProduct f = new FindProduct(this, true);
        f.setVisible(true);
        f.setLocationRelativeTo(this);
    }//GEN-LAST:event_btnFindActionPerformed
    private boolean check = true;

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditActionPerformed
        // TODO add your handling code here:
        if (check) {
            btnFind.setEnabled(false);
            btnNew.setEnabled(false);
            btnDelete.setEnabled(false);
            txtPname.setBackground(Color.yellow);
            txtDescription.setBackground(Color.yellow);
            cboLanguage.setBackground(Color.yellow);
            cboSupplier.setBackground(Color.yellow);
            cboStatus.setBackground(Color.yellow);
            btnEdit.setText("Update");
            check = false;
        } else {
            if (!CheckValidate()) {
                return;
            }
            String chon = txtProdID.getText();
            String name = txtPname.getText();
            String des = txtDescription.getText();
            String lang = String.valueOf(cboLanguage.getSelectedItem());
            Supplier s = modelProduct.getSup(String.valueOf(cboSupplier.getSelectedItem()));
            int sup = s.getSupID();
            int status = Integer.parseInt(String.valueOf(cboStatus.getSelectedIndex()));
            if (modelProduct.checkExists(name, chon) > 0) {
                if (modelProduct.editProduct(chon, name, sup, des, lang, status)) {
                    JOptionPane.showMessageDialog(this, "Update Successfully !");
                } else {
                    JOptionPane.showMessageDialog(this, "Fail !");
                }
            }
            else{
                JOptionPane.showMessageDialog(this, "This product already exists");
            }
            initProdID();
            btnFind.setEnabled(false);
            btnNew.setEnabled(false);
            btnDelete.setEnabled(false);
            txtPname.setBackground(Color.white);
            txtDescription.setBackground(Color.white);
            cboLanguage.setBackground(Color.white);
            cboSupplier.setBackground(Color.white);
            cboStatus.setBackground(Color.white);
            btnEdit.setText("Edit");
            check = true;
        }
    }//GEN-LAST:event_btnEditActionPerformed

    private void btnNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewActionPerformed
        // TODO add your handling code here:
        new AddProduct(this, true).setVisible(true);
    }//GEN-LAST:event_btnNewActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmProduct.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new frmProduct().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnFind;
    private javax.swing.JButton btnNew;
    private javax.swing.JComboBox cbTypeID;
    private javax.swing.JComboBox cbTypeLang;
    private javax.swing.JPanel cbTypeProd;
    private javax.swing.JComboBox cbTypeProdID;
    private javax.swing.JComboBox cboLanguage;
    private javax.swing.JComboBox cboStatus;
    private javax.swing.JComboBox cboSupplier;
    private javax.swing.JCheckBox cbxFriday;
    private javax.swing.JCheckBox cbxMonday;
    private javax.swing.JCheckBox cbxSaturday;
    private javax.swing.JCheckBox cbxSunday;
    private javax.swing.JCheckBox cbxThursday;
    private javax.swing.JCheckBox cbxTuesday;
    private javax.swing.JCheckBox cbxWednesday;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JList lstType;
    private javax.swing.JPanel panelRateMagz;
    private javax.swing.JPanel panelRateNews;
    private javax.swing.JTextArea txtDescription;
    private javax.swing.JTextField txtMagzRate;
    private javax.swing.JTextField txtPname;
    private javax.swing.JTextField txtProdID;
    // End of variables declaration//GEN-END:variables
}
